package cn.edu.scujcc.staffdiary.ui.clock;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.jetbrains.annotations.NotNull;
import cn.edu.scujcc.staffdiary.R;

public class ClockRvAdapter extends RecyclerView.Adapter<ClockRvAdapter.ClockRowHolder> {

    @NotNull
    @Override
    public ClockRowHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View rowView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.clock_row,parent,false);
        ClockRowHolder holder = new ClockRowHolder(rowView);
        return holder;
    }

    @Override
    public int getItemCount() {
        return ClockLab.get().getClockCount();
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ClockRowHolder holder, int position) {
        Clock c = ClockLab.get().getClock(position);
        holder.bind(c);
    }

    public class ClockRowHolder extends RecyclerView.ViewHolder{
        private TextView name; //打卡人名字
        private TextView time; //打卡时间
        public ClockRowHolder(@NonNull @NotNull View row) {
            super(row);
            this.name = row.findViewById(R.id.clock_name);
            this.time = row.findViewById(R.id.clock_time);
        }

        public void bind(Clock c){
            this.name.setText(c.getClockname());
            this.time.setText(c.getClocktime());
        }
    }
}
